﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using WaveMaster.Holidays.Club.Gateway;
using WaveMaster.Holidays.Club.Service;
namespace WaveMaster.Holidays.Club.Web
{
    public class ServiceFactory
    {
        Hashtable m_userControlCollection = new Hashtable();
        DataBaseConnectivity m_dataBaseConectivity;

        static volatile ServiceFactory m_instance;
        public const string USERSERVICE = "USER_SERVICE";
        public const string TRAVEL_AGENT_SERVICE = "TRAVEL_AGENT_SERVICE";
        public const string TICKET_PURCHASE_SERVICE = "TICKET_PURCHASE_SERVICE";
        public const string PASSPORT_SERVICE = "PASSPORT_SERVICE";
        public const string SEAPORT_SERVICE = "SEAPORT_SERVICE";
        public const string VESSEL_SERVICE = "VESSEL_SERVICE";
        public const string TRIP_SERVICE = "TRIP_SERVICE";
        public const string BOOKING_SERVICE = "BOOKING_SERVICE";
        public const string MEMBER_TYPE_SERVICE = "MEMBER_TYPE_SERVICE";
        public const string TICKET_DEDUCTION_SERVICE = "TICKET_DEDUCTION_SERVICE";
        public const string CONFIGURATION_SERVICE = "CONFIGURATION_SERVICE";

        public ServiceFactory()
        {
            m_dataBaseConectivity = new DataBaseConnectivity();
        }
        public static ServiceFactory Instance()
        {
            if (m_instance == null)
            {
                m_instance = new ServiceFactory();
            }
            return m_instance;
        }
        public IService GetServiceXX(string key)
        {

                IService svc = (IService)m_userControlCollection[key];
                if (svc == null)
                {
                    switch (key)
                    {
                        case USERSERVICE:
                            m_userControlCollection.Add(key, new UserService(m_dataBaseConectivity));
                            break;
                        case TRAVEL_AGENT_SERVICE:
                            m_userControlCollection.Add(key, new TravelAgentService(m_dataBaseConectivity));
                            break;
                        case TICKET_PURCHASE_SERVICE:
                            m_userControlCollection.Add(key, new TicketPurchaseService(m_dataBaseConectivity));
                            break;
                        case PASSPORT_SERVICE:
                            m_userControlCollection.Add(key, new PassportService(m_dataBaseConectivity));
                            break;
                        case VESSEL_SERVICE:
                            m_userControlCollection.Add(key, new VesselService(m_dataBaseConectivity));
                            break;
                        case SEAPORT_SERVICE:
                            m_userControlCollection.Add(key, new SeaPortService(m_dataBaseConectivity));
                            break;
                        case TRIP_SERVICE:
                            m_userControlCollection.Add(key, new TripService(m_dataBaseConectivity));
                            break;
                        case BOOKING_SERVICE:
                            m_userControlCollection.Add(key, new CheckInService(m_dataBaseConectivity));
                            break;
                        case MEMBER_TYPE_SERVICE:
                            m_userControlCollection.Add(key, new MemberTypeService(m_dataBaseConectivity));
                            break;
                        case TICKET_DEDUCTION_SERVICE:
                            m_userControlCollection.Add(key, new TicketDeductionService(m_dataBaseConectivity));
                            break;
                        case CONFIGURATION_SERVICE:
                            m_userControlCollection.Add(key, new ConfigurationService(m_dataBaseConectivity));
                            break;
                    }
                }
                svc = (IService)m_userControlCollection[key];
                return svc;

        }
        public IService GetService(string key)
        {
            //IService svc = (IService)m_userControlCollection[key];
            //if (svc == null)
            // {
            switch (key)
            {
                case USERSERVICE:
                    return new UserService();
                case TRAVEL_AGENT_SERVICE:
                    return new TravelAgentService();
                case TICKET_PURCHASE_SERVICE:
                    return new TicketPurchaseService();
                case PASSPORT_SERVICE:
                    return new PassportService();
                case VESSEL_SERVICE:
                    return new VesselService();
                case SEAPORT_SERVICE:
                    return new SeaPortService();
                case TRIP_SERVICE:
                    return new TripService();
                case BOOKING_SERVICE:
                    return new CheckInService();
                case MEMBER_TYPE_SERVICE:
                    return new MemberTypeService();
                case TICKET_DEDUCTION_SERVICE:
                    return new TicketDeductionService();
                case CONFIGURATION_SERVICE:
                    return new ConfigurationService();
            }
            return null;
        }
        public static int GenerateRandomID()
        {
            Random random = new Random();
            return random.Next(1000, 9999);
        }
    }
}